package util.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import util.enumeration.FnbType;

@FacesConverter(value = "fnbTypeConverter", forClass = util.enumeration.FnbType.class)
public class FnbTypeConverter implements Converter {

    public Object getAsObject(FacesContext context, UIComponent component, String value) {    

        if (value == null || value.length() == 0) {
            return null;
        }

        if(value.equals("BISTRO")) return FnbType.BISTRO;
        else if(value.equals("BUFFET")) return FnbType.BUFFET;
        else if(value.equals("CAFE")) return FnbType.CAFE;
        else if(value.equals("CAFETERIA")) return FnbType.CAFETERIA;
        else if(value.equals("CASUALDINING")) return FnbType.CASUALDINING;
        else if(value.equals("COFFEEHOUSE")) return FnbType.COFFEEHOUSE;
        else if(value.equals("COFFEESHOP")) return FnbType.COFFEESHOP;
        else if(value.equals("FAMILYSTYLE")) return FnbType.FAMILYSTYLE;
        else if(value.equals("FASTCASUAL")) return FnbType.FASTCASUAL;
        else if(value.equals("FASTFOOD")) return FnbType.FASTFOOD;
        else if(value.equals("FINEDINING")) return FnbType.FINEDINING;
        else if(value.equals("FOODCOURT")) return FnbType.FOODCOURT;
        else if(value.equals("HAWKERCENTRE")) return FnbType.HAWKERCENTRE;
        else if(value.equals("PUB")) return FnbType.PUB;
        else if(value.equals("SELECT")) return FnbType.SELECT;
        else if(value.equals("TEAHOUSE")) return FnbType.TEAHOUSE;
        else return FnbType.SELECT;
    }

    public String getAsString(FacesContext context, UIComponent component, Object value) {

        if (value == null) {
            return null;
        }

        if (value instanceof FnbType) {
            FnbType fnbType = (FnbType) value;

            if(fnbType.equals(FnbType.BISTRO)) return "BISTRO";
            else if(fnbType.equals(FnbType.BUFFET)) return "BUFFET";
            else if(fnbType.equals(FnbType.CAFE)) return "CAFE";
            else if(fnbType.equals(FnbType.CAFETERIA)) return "CAFETERIA";
            else if(fnbType.equals(FnbType.CASUALDINING)) return "CASUALDINING";
            else if(fnbType.equals(FnbType.COFFEEHOUSE)) return "COFFEEHOUSE";
            else if(fnbType.equals(FnbType.COFFEESHOP)) return "COFFEESHOP";
            else if(fnbType.equals(FnbType.FAMILYSTYLE)) return "FAMILYSTYLE";
            else if(fnbType.equals(FnbType.FASTCASUAL)) return "FASTCASUAL";
            else if(fnbType.equals(FnbType.FASTFOOD)) return "FASTFOOD";
            else if(fnbType.equals(FnbType.FINEDINING)) return "FINEDINING";
            else if(fnbType.equals(FnbType.FOODCOURT)) return "FOODCOURT";
            else if(fnbType.equals(FnbType.HAWKERCENTRE)) return "HAWKERCENTRE";
            else if(fnbType.equals(FnbType.PUB)) return "PUB";
            else if(fnbType.equals(FnbType.SELECT)) return "SELECT";
            else if(fnbType.equals(FnbType.TEAHOUSE)) return "TEAHOUSE";
            else return "SELECT";
        }
        else {
            throw new IllegalArgumentException("object " + value + " is of type " + value.getClass().getName() + "; expected type: util.enumeration.FnbType");
        }
    }
}